/**
 * 对用户提供一些方法
 */
import controConfig from "./controConfig";
import sugar from "../kernel/tools/sugar";
import {configApi} from '../gem'
let api:configApi = {
    addRouter,
    setController,
    setMiddleware,
    setAnnotation,
    setPublic,
    addMiddleware,
    addGlobalMiddleware,
    addrunAnnotation,
    addAnnotation,
    addSugar,
    setFeatures
}
export default api;

// 添加路由文件
export function addRouter(data:any):void{
    if(typeof data === "string"){
        controConfig.addrouteConfig({path:sugar.path(data,{superNumber:3}),middleware:[],prefix:""})
    }else{
        // 初始化配置
        data.path = sugar.path(data.path,{superNumber:3});
        data.prefix || (data.prefix="")
        data.middleware || (data.middleware=[])
        controConfig.addrouteConfig(data);
    }
}

// 添加控制器文件夹地址
export function setController(str:string):void{
    controConfig.addAddress("controller",sugar.path(str,{superNumber:3}));
}

// 设置中间件的文件夹地址
export function setMiddleware(str:string):void{
    controConfig.addAddress("middleware",sugar.path(str,{superNumber:3}));
}

// 设置注解的文件夹地址
export function setAnnotation(str:string):void{
    controConfig.addAddress("annotation",sugar.path(str,{superNumber:3}));
}

// 配置公共地址
export function setPublic(path:string):void{
    controConfig.addAddress("public",sugar.path(path,{superNumber:3}))
}

// 添加中间件
export function addMiddleware(id:string,data:string|Function):void{
    controConfig.addMiddleware(id,data)
}
// 添加全局中间件
export function addGlobalMiddleware(data:string|Function):void{
    controConfig.addGlobal_Middleware(data)
}
// 添加注解的运行地址
export function addrunAnnotation(path:string):void{
    controConfig.addrunAnnotation(sugar.path(path,{superNumber:3}));
}

// 添加一个注解
export function addAnnotation(name:string,obj:any):void{
    controConfig.addAnnotation(name,obj)
}

// 添加语法糖地址
export function addSugar(name:string,path:string):void{
    controConfig.addpathSugar(name,sugar.path(path,{superNumber:3}));
}

// 设置特性
export function setFeatures(option:any):void{
    for(let key in option){
        controConfig.setFeatures(key,option[key])
    }
}

